//
//  ZJVideoCoverView.m
//  ZhongWangYuanApp
//
//  Created by ZJ on 2018/6/4.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "ZJVideoCoverView.h"
@interface ZJVideoCoverView (){
    UIView *_bgView;
}
/** 背景 */
@property (nonatomic, strong) UIImageView  *bgImageView;
/** 播放按钮 */
@property (nonatomic, strong) UIButton  *playerButton;
/** 时长label */
@property (nonatomic, strong) UILabel  *label;

@end
@implementation ZJVideoCoverView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    [self addSubview:self.bgImageView];
    
    _bgView = [UIView new];
    _bgView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
    
    [self addSubview:_bgView];
    
    [self addSubview:self.playerButton];
    [self addSubview:self.label];

    self.bgImageView.sd_layout
    .topSpaceToView(self, 0)
    .leftEqualToView(self)
    .rightEqualToView(self)
    .bottomEqualToView(self);
    
    _bgView.sd_layout
    .topSpaceToView(self, 0)
    .leftEqualToView(self)
    .rightEqualToView(self)
    .bottomEqualToView(self);
    
    self.playerButton.sd_layout
    .widthIs(60 * [UIScreen zj_screenHScale])
    .heightEqualToWidth()
    .centerXEqualToView(self)
    .centerYEqualToView(self);
    
    self.label.sd_layout
    .topSpaceToView(self.playerButton, 10 * [UIScreen zj_screenHScale])
    .leftEqualToView(self)
    .rightEqualToView(self)
    .heightIs([NSString heightWithTextFont:self.label.font]);
}

- (void)action_button{
    [self hiddenViews];
    if (self.delegate) {
        [self.delegate ZJVideoCoverViewDelegate_player];
    }
}


- (void)setBgImageViewURL:(NSString *)imageViewURl timeString:(NSString *)timeString{
    [self.bgImageView sd_setImageWithURL:CREATEURL(imageViewURl) placeholderImage:PlaceholderBIGImage];
    self.label.text = [NSString isNilStringReturnString:timeString ];
}

- (void)showViews{
    self.playerButton.hidden = NO;
    _bgView.hidden = NO;
    self.label.hidden = NO;
}

- (void)hiddenViews{
    self.playerButton.hidden = YES;
    _bgView.hidden = YES;
    self.label.hidden = YES;
}
#pragma mark - Getters
- (UIImageView *)bgImageView{
    if (_bgImageView == nil){
        _bgImageView = [UIImageView new];
        _bgImageView.contentMode = UIViewContentModeScaleAspectFill;
        _bgImageView.clipsToBounds = YES;
    }
    return _bgImageView;
}
- (UIButton *)playerButton{
    if (_playerButton == nil){
        _playerButton = [UIButton new];
        [_playerButton addTarget:self action:@selector(action_button) forControlEvents:UIControlEventTouchUpInside];
        [_playerButton setImage:[UIImage imageNamed:@"plv_vod_btn_play_60"] forState:UIControlStateNormal];
    }
    return _playerButton;
}

- (UILabel *)label{
    if (_label == nil){
        _label  = [UILabel new];
        _label.textColor = [UIColor themeWhiteColor];
        _label.font = LYPFONT(18);
        _label.textAlignment = NSTextAlignmentCenter;
    }
    return _label;
}


@end
